from django.db import models


# class User(models.Model):
#     u_name = models.CharField(max_length=50,unique=True)
#     u_password = models.CharField(max_length=200)
#     u_email = models.EmailField(max_length=200,unique=True)
#     def __str__(self):
#         return self.u_name

class Professor(models.Model):
    id = models.CharField(max_length=20, primary_key=True)
    name = models.CharField(max_length=100)

    def __str__(self):
        return self.id+':'+self.name


class Time(models.Model):
    year = models.PositiveIntegerField()
    semester = models.PositiveIntegerField(choices=((1, 'semester 1'),(2, 'semester 2'),(3, 'semester 3')),default=1)

    def __str__(self):
        return str(self.year) + ' semester' + str(self.semester)

    class Meta:
        unique_together=("year","semester")


class Module(models.Model):
    code = models.CharField(max_length=50)
    name = models.CharField(max_length=100)

    def __str__(self):
        return self.code + ' ' + self.name

    class Meta:
      unique_together=("code","name")


class Module_Instance(models.Model):
    module = models.ForeignKey("Module", on_delete=models.CASCADE)
    open_times = models.ForeignKey("Time", on_delete=models.CASCADE,default=None)
    teaching_professors = models.ManyToManyField(Professor)


class Rating(models.Model):
    module = models.ForeignKey("Module_Instance", on_delete=models.CASCADE)
    professor = models.ForeignKey("Professor", on_delete=models.CASCADE)
    user_id = models.IntegerField()
    rating = models.PositiveSmallIntegerField()

    class Meta:
      unique_together=("module","professor","user_id")
